﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using Soundteller.Visual.Model;
using Soundteller.Visual.Repositories.Interfaces;
using Soundteller.Visual.Services.Interfaces;

namespace Soundteller.Visual.Services
{
    public class Drawer : IDrawer
    {
        private readonly IGraphicBufferRepository _graphicBufferRepository;

        public Drawer(IGraphicBufferRepository graphicBufferRepository)
        {
            if (graphicBufferRepository == null) throw new ArgumentNullException("graphicBufferRepository");

            _graphicBufferRepository = graphicBufferRepository;
        }

        public void Draw(GraphicBase graphic)
        {
            Debug.WriteLine("{0}.Draw( {1} )", GetType(), graphic);

            if (graphic == null) throw new ArgumentNullException("graphic");
            if (string.IsNullOrWhiteSpace(graphic.Name)) throw new ArgumentException("graphic.Name cannot be empty", "graphic");

            _graphicBufferRepository.Push(graphic);
        }


        public void Draw(IEnumerable<GraphicBase> graphics)
        {
            foreach (var graphic in graphics)
            {
                Draw(graphic);

                Draw(graphic.InnerGraphics);
            }
        }
    }
}
